﻿using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Xml.Serialization;

namespace SilverCrmSoap.FetchXml
{
    
    [DebuggerStepThrough]
    [XmlType(AnonymousType = true)]
    [XmlRoot(Namespace = "", IsNullable = false)]
    public class Filter
    {
        public Filter()
        {
            JoinType = FilterJoinType.And;
            if (Conditions == null) Conditions = new List<Condition>();
        }

        public Filter(Condition singleCondition)
        {
            JoinType = FilterJoinType.And;
            if (Conditions == null) Conditions = new List<Condition>();
            Conditions.Add(singleCondition);
        }
        
        [XmlElement("condition", typeof(Condition))]
        public List<Condition> Conditions { get; set; }

        [XmlElement("filter", typeof (Filter))]
        public List<Filter> Filters { get; set;}
        
        [XmlAttribute("type"), DefaultValue(FilterJoinType.And)]
        public FilterJoinType JoinType { get; set; }

        [XmlAttribute("isquickfindfields")]
        public bool IsQuickfindFields { get; set; }

        [XmlIgnore]
        public bool IsQuickfindFieldsSpecified { get; set; }
    }
}